/**
 * 
 */
package com.gopay.common.user.payee.dao.impl;


import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.domain.cps.transfer.GopayPayee;


/**
 * @CpsTransReceiver00900QueryDAO.java
 * @author xiefei
 * @2013-3-11 下午2:33:33  www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("cpsTransReceiver00900QueryDAO")
public class CpsTransReceiver00900QueryDAOImpl extends BaseDAOImpl<GopayPayee, Integer> implements
        com.gopay.common.user.payee.dao.CpsTransReceiver00900QueryDAO {

    @Override
    public List<GopayPayee> findByCustIdPageList(String custId, String custType, int pageSize, int pageNo,String rCustId,String rGopayAcct) {
        DetachedCriteria criteria = DetachedCriteria.forClass(GopayPayee.class);
        criteria.add(Restrictions.eq("payerCustId",custId));
        criteria.add(Restrictions.eq("payerCustType",custType));
        if(!StringUtils.isBlank(rCustId)){
            criteria.add(Restrictions.like("receiverCustId",rCustId,MatchMode.ANYWHERE));
        }
        if(!StringUtils.isBlank(rGopayAcct)){
            criteria.add(Restrictions.like("receiverGopayAcct",rGopayAcct,MatchMode.ANYWHERE));
        }
        return this.findByCriteria(criteria, pageNo, pageSize);

    }

    /* (non-Javadoc)
     * @see com.gopay.common.cps.dao.tran.CpsTransReceiver00900QueryDAO#findByCustIdCount(java.lang.String, java.lang.String)
     */
    @Override
    public int findByCustIdCount(String custId, String custType,String rCustId,String rGopayAcct) {
        DetachedCriteria criteria = DetachedCriteria.forClass(GopayPayee.class);
        criteria.add(Restrictions.eq("payerCustId",custId));
        criteria.add(Restrictions.eq("payerCustType",custType));
        if(!StringUtils.isBlank(rCustId)){
            criteria.add(Restrictions.like("receiverCustId",rCustId,MatchMode.ANYWHERE));
        }
        if(!StringUtils.isBlank(rGopayAcct)){
            criteria.add(Restrictions.like("receiverGopayAcct",rGopayAcct,MatchMode.ANYWHERE));
        }
        return this.findCountByCriteria(criteria);
    }

    /* (non-Javadoc)
     * @see com.gopay.common.cps.dao.tran.CpsTransReceiver00900QueryDAO#findByCustIdAndRgopayAcct(java.lang.String, java.lang.String)
     */
    @Override
    public List<GopayPayee> findByCustIdAndRgopayAcct(String custId, String rGopayAcct) {
        DetachedCriteria criteria = DetachedCriteria.forClass(GopayPayee.class);
        criteria.add(Restrictions.eq("payerCustId",custId));
        criteria.add(Restrictions.eq("receiverGopayAcct",rGopayAcct));
        return this.findByCriteria(criteria);
    }

}
